<template>
    <div class="warnning-edit contain-edit">
        <div class="header">
           <p>预警管理>>设置预警管理</p>
        </div>
       <div class="main">
           <el-form :model="information" :rules="rules" ref="information" label-width="120px" class="">
                <el-form-item label="收租时间：" prop="day">
                   <el-input type="text"
                        style="width:100px;margin:0 20px"
                        placeholder="数字1-30"
                        v-model.number="information.day">
                    </el-input>
                </el-form-item>
                <el-form-item label="月租到期未交提醒期限：" prop="longDay">
                    <el-input
                        type="text"
                        style="width:100px;margin:0 20px"
                        placeholder="天"
                        v-model.number="information.longDay">
                    </el-input><span>根据房东设置的收租时间</span>
                </el-form-item>
                <el-form-item label="合同即将到期提醒期限：" prop="concatDay">
                    <el-input
                        type="text"
                        style="width:100px;margin:0 20px"
                        placeholder="天"
                        v-model.number="information.concatDay">
                    </el-input><span>根据合同签订时间和期限</span>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('information')"  :loading="loading">保存</el-button>
                </el-form-item>
           </el-form>
       </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js');
let common = require("../../common.js");
  export default {
    data() {
        return {
            information:{
                day:'',
                longDay:'',
                concatDay:''
            },
            rules: {
                day: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                longDay: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                concatDay: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ]
            },
            loading: false
        };
    },
    components:{
      
    },
    watch:{
    },
    mounted() {
        this.getDetail(); 
        this.getDetail1(); 
        this.getDetail2(); 
    },
    methods: {
        getDetail(){
            let url =  CONSTANT.URL.L_SYSVAR.FINDRENTDAY
           let data = {} ;
           common.requestAjax(url,JSON.stringify(data),null,(res)=>{
               this.information.day = res.data.bussData;
           }) 
        },
        getDetail1(){
            let url =  CONSTANT.URL.L_SYSVAR.FINDLONGRENTWARNDAY
           let data = {} ;
           common.requestAjax(url,JSON.stringify(data),null,(res)=>{
               this.information.longDay = res.data.bussData;
           }) 
        },
        getDetail2(){
            let url =  CONSTANT.URL.L_SYSVAR.FINDWARNDAY
           let data = {} ;
           common.requestAjax(url,JSON.stringify(data),null,(res)=>{
               this.information.concatDay = res.data.bussData;
           }) 
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.loading = true;
                var url = CONSTANT.URL.L_SYSVAR.SETRENTDAY;
                common.requestAjax(url, {}, {day:this.information.day}, res => {
                    if(res.status == 200) {
                  
                    } else {
                
                    }
                });
                var url2 = CONSTANT.URL.L_SYSVAR.SETLONGRENTWARNDAY;
                common.requestAjax(url2, {}, {day:this.information.longDay}, res => {
                    if(res.status == 200) {
        
                    } else {

                    }
                });
                var url3 = CONSTANT.URL.L_SYSVAR.SETCONTRACTWARNDAY;
                common.requestAjax(url3, {}, {day:this.information.concatDay}, res => {
                    if(res.status == 200) {
                        this.$message({
                            type: 'success',
                            message: '保存成功!'
                        });
                        this.loading = false;
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.msg
                        });
                        this.loading = false;
                    }
                });
            } else {
                console.log('error submit!!');
                return false;
            }
            });
        },
    }
  }
</script>

<style lang="scss" >
    .el-form-item__content{
        margin-left: 0;
    }
    .warnning-edit{
        .el-form-item__label{
            width: 200px!important;
        }
    }
</style>